<?php
	class order_record extends spModel{
		var $pk = "id"; // 每个学年唯一的标志，可以称为主键
		var $table = "order_record"; // 数据表的名称

		var $join = array(
			'sys_student_info' => array(
				'mapkey' => 'uid',
				'fkey' => 'student_id'
			)
		);
	       
	    var $validator = array(
			"rules" => array(
				'time' => array(
					'required' => true
				),
				'cato_id' => array(
					'required' => true
				)
			),
			"messages" => array( // 提示信息
				'time' => array(
					'required' => '时间段不能为空'
				),
				'cato_id' => array(
					'required' => '禁用目录不能为空'
				)
			)
		);
		
		public function checkName($name){
			if($this->find(array('name'=>$name))){
				return false;
			}	
			else{
				return true;
			}	
		}

		public function getInfoById($id){
			$data_rs = $this->find(array("id"=>$id));
			if($data_rs){
				$data_rs["time_array"] = explode(",", $data_rs["time"]);
				$data_rs["cato_array"] = explode(",", $data_rs["cato_id"]);
				$data_rs["course_array"] = explode(",", $data_rs["course_id"]);
				$data_rs["test_array"] = explode(",", $data_rs["test_id"]);
			}
			return $data_rs;
		}

		public function getInfoByIdForStatus1($id){
			$data_rs = $this
				->join("sys_student_info", "sys_student_info.uid = sys_order_record.student_id")
				->join("sys_cato_course as menu", "menu.id = sys_order_record.cato_id and menu.level_id = 1")
				->join("sys_cato_course as course", "course.id = sys_order_record.course_id and course.level_id = 2")
				->join("sys_cato_course as test", "test.id = sys_order_record.test_id and test.level_id = 3")
				->join("sys_course_time", "sys_course_time.id = sys_order_record.time")
				->find(array("sys_order_record.id"=>$id, "sys_order_record.status"=>1), null, "sys_order_record.*, sys_student_info.classname as student_classname, sys_student_info.phone as student_phone, sys_student_info.name as student_name, menu.name as menu_name, course.name as course_name, test.name as test_name, sys_course_time.name as course_time_name");
			if($data_rs){
				if($data_rs["order_endtime"] < time()){
					$data_rs["canModify"] = 0;
				}else{
					$data_rs["canModify"] = 1;
				}
			}
			return $data_rs;
		}
	}
?>